<?php

namespace Home\Controller;

use \Think\Controller;
use Tools\AuthController;

class MainController extends AuthController
{
    function method_list()
    {
        if (!empty(cookie("username"))) {
            $user = D('ssg_account');
            $role = $user->where("account ='" . cookie("username") . "'")->field("roleId")->find();
            $model_operate = D('ssg_role_modules_operate');
            $module = D('ssg_modules');
            if ($role['roleId'] == 1) {
                $auth_par = $module->where("level=0")->select();
                $auth_son = $module->where("level=1")->select();
            } else {
                $model_method = $model_operate->where('roleId= ' . $role['roleId'])->field('role_auth_id')->find();
                $arr = explode(",", $model_method['role_auth_id']);
                $auth_par = array();
                $auth_son = array();
                foreach ($arr as $k => $v) {
                    $auth_par[] = $module->where("level=0 and id='" . $v . "'")->find();
                    $auth_son[] = $module->where("level=1 and id='" . $v . "'")->find();
                }
            }
            $this->assign("auth_par", $auth_par);
            $this->assign("auth_son", $auth_son);
        }
        $this->display();
    }

    function outlogin()
    {
        cookie("username",null);
        if(empty(cookie("username"))){
            $this->redirect('Index/index', array(), 0);
        }else{
            echo "退出失败";
        }
    }
}